package controllers;

import java.util.List;

import models.CommercialOfferer;
import models.Event;
import models.Offer;
import models.PrivateOfferer;
import models.User;
import play.mvc.*;

@With(Secure.class)
public class AdminInterface extends Controller {

	public static void index() {
		User user = Security.getConnected();
		
		if (user instanceof models.Admin) {
			long offerCount = Offer.count();
			long privateOffererCount = PrivateOfferer.count();
			long commercialOffererCount = CommercialOfferer.count();
			long eventCount = Event.count();
			
			render(user, offerCount, privateOffererCount, commercialOffererCount, eventCount);
		} else
			Application.index(null, null, null);
	}
	
    public static void showEvents() {
        User user = Security.getConnected();
        
        if (user instanceof models.Admin) {
            List<Event> events = Event.findAll();
        	render(user, events);
        } else
        	Application.index(null, null, null);
    }
    
    public static void showInactiveEvents() {
    	User user = Security.getConnected();
    	
    	if (user instanceof models.Admin) {
    		List<Event> events = Search.searchUpcomingInactiveEvents();
    		render(user, events);
    	} else
    		Application.index(null, null, null);
    }
    
    public static void showOffers(long eventId) {
    	Event event = Event.findById(eventId);
    	User user = Security.getConnected();
    	
    	List<Offer> offers = event.offers;
    	
    	if (user instanceof models.Admin)
        	render(user, event, offers);
        else
        	Application.index(null, null, null);
    }
    
    public static void showUsers() {
    	User user = Security.getConnected();
    	
    	if (user instanceof models.Admin) {
    		List<User> members = User.findAll();
    		render(user, members);
    	}
    }

}
